cd "..."
use "...dta", clear

************************************************************************************************************
**********************			GETTING MODERATION INDICES *************************************************
************************************************************************************************************

* The .dta file with scores is provided (moderator_factors.dta). You do not need to re-run the code below.

/*
rename ord ord_x
gen ord = _n
* GOAL: use some of the variables that compose the items below to get an index for SES/struggle
/*
LIST OF ALL MODERATORS TESTED:
Child gender	X
Child age	    X
(i)father school type            ------	i.fb_q1_edu
father highest grade             ------ c.fb_grade
father literacy	                 ------ i.fb_q4_ed
PREI housing resources            -----	c._1_hh_res (excludes prei14 - petty crime)
PREI housing quality             ------	c._1_hh_qua		
Financial worry		             ------	c._1_mb_q2_fin (higher is more worry)
Mother reported stim environ	 ------	c.b_sti_m	
Mother health    X               ------ _1_mb_q1_hunger (higher is better health). 
*/


rename _1_mb_q2_fin imp_mb_q2_fin 
rename _1_mb_q1_hunger imp_mb_q1_hunger


*removing stimulation and mother health because they are obviously a different construct
runmplus mb_q1_prei mb_q2_prei mb_q3_prei mb_q4_prei mb_q5_prei mb_q6_prei mb_q7_prei ///
mb_q8_prei mb_q9_prei mb_q10_prei mb_q11_prei mb_q12_prei  mb_q13_prei  ///
mb_q15_prei ///
fb_q1_edu fb_grade fb_q4_ed imp_mb_q2_fin , idvariable(hhid_final) ///
type (efa 1 3) ///
categorical (mb_q1_prei mb_q2_prei mb_q3_prei mb_q4_prei mb_q5_prei mb_q6_prei mb_q7_prei ///
mb_q8_prei mb_q9_prei mb_q10_prei mb_q11_prei mb_q12_prei  mb_q13_prei ///
mb_q15_prei fb_q1_edu fb_q4_edu) ///
missing =. standardized modindices(all) ///
return list

/*

2F-sol (education vs all prei and financial worry; bad fit)

 MB_Q1_PR       0.451*        0.046
 MB_Q2_PR      -0.270*       -0.063*
 MB_Q3_PR       0.362*       -0.057
 MB_Q4_PR       0.512*        0.097*
 MB_Q5_PR       0.557*       -0.036
 MB_Q6_PR       0.318*        0.055.  *** DROP?
 MB_Q7_PR       0.653*        0.013
 MB_Q8_PR       0.603*       -0.013
 MB_Q9_PR       0.746*        0.008
 MB_Q10_P       0.770*       -0.072*
 MB_Q11_P       0.857*       -0.029
 MB_Q12_P       0.848*        0.028
 MB_Q13_P       0.436*        0.004
 MB_Q15_P       0.285*       -0.026		*** DROP?
 FB_Q1_ED      -0.035         0.582*
 FB_GRADE      -0.004*        0.966*
 FB_Q4_ED       0.044*        0.830*
 IMP_MB_Q      -0.258*       -0.192*

 3F-sol (education, housing quality, housing resources+financial worry)
 MB_Q1_PR       0.081         0.487*        0.016
 MB_Q2_PR       0.153*       -0.511*       -0.036
 MB_Q3_PR      -0.010         0.465*       -0.085*
 MB_Q4_PR       0.035         0.623*        0.061
 MB_Q5_PR       0.062         0.650*       -0.083
 MB_Q6_PR       0.146*        0.239*        0.039	DROP
 MB_Q7_PR       0.579*        0.149*        0.010
 MB_Q8_PR       0.176*        0.586*       -0.058
 MB_Q9_PR       0.740*        0.049         0.020
 MB_Q10_P       0.777*        0.022        -0.060*
 MB_Q11_P       0.917*       -0.061*       -0.003
 MB_Q12_P       0.868*       -0.005         0.053*
 MB_Q13_P      -0.026         0.593*       -0.034
 MB_Q15_P       0.017         0.346*       -0.049	DROP
 FB_Q1_ED       0.039        -0.094*        0.591*
 FB_GRADE      -0.007        -0.001         0.967*
 FB_Q4_ED      -0.001         0.053*        0.826*
 IMP_MB_Q       0.186*       -0.546*       -0.175*

*/

* Drop access to electricity (PREI 6)and help from others (PREI 15)
runmplus mb_q1_prei mb_q2_prei mb_q3_prei mb_q4_prei mb_q5_prei mb_q7_prei ///
mb_q8_prei mb_q9_prei mb_q10_prei mb_q11_prei mb_q12_prei  mb_q13_prei ///
fb_q1_edu fb_grade fb_q4_ed imp_mb_q2_fin , idvariable(hhid_final) ///
type (efa 1 3) ///
categorical (mb_q1_prei mb_q2_prei mb_q3_prei mb_q4_prei mb_q5_prei mb_q7_prei ///
mb_q8_prei mb_q9_prei mb_q10_prei mb_q11_prei mb_q12_prei  mb_q13_prei ///
 fb_q1_edu fb_q4_edu) ///
missing =. standardized modindices(all) ///
return list

* Factor scores are extracted for an ses factor and an education factor. See (moderator_factors.dta)
*/




*		Running the moderations


* The code below runs the models for all father outcomes using child gender as a moderator.

* The other moderators we ran in the study are:
*		c.child_age 
*		c.mod_edu 
*		c.mod_ses  
*		c.b_sti_m 
*		1_mb_q1_hunger (caregiver health) higher is better health

* We ran the same moderators for mother reported outcomes as well.



*prepping for merge
use "publication_data.dta", clear
rename ord ord_x
gen ord = _n

merge 1:1 ord using "moderator_factors.dta"


************************************************************************************************************
**********************			FATHER REPORT 		********************************************************
************************************************************************************************************

*--------------------------------child gender


/*PHQ*/ 

*POOLED
mixed fe_PHQ fb_PHQ i.tx##i._1_child_fem camp ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
camp#c._1_f_age camp#i.fb_q1_edu camp#i.fb_grade camp#i.fb_q4_edu ///
camp#_1_child_fem camp#c.child_age ///
camp#i._1_mb_q1_hunger camp#_1_mb_q2_hunger camp#_1_mb_q4_pregnant camp#c._1_mb_child_count ///
camp#_1_mb_q2_fin camp#c._1_hh_res camp#c._1_hh_qua  ///
|| mvid: ||clu2:
testparm i.tx#i._1_child_fem



*HOST
mixed fe_PHQ fb_PHQ i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==0
testparm i.tx#i._1_child_fem

*CAMP
mixed fe_PHQ fb_PHQ i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==1
testparm i.tx#i._1_child_fem

/*GAD*/ 
 *POOLED
mixed fe_GAD i.tx##i._1_child_fem camp ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
camp#c._1_f_age camp#i.fb_q1_edu camp#i.fb_grade camp#i.fb_q4_edu ///
camp#_1_child_fem camp#c.child_age ///
camp#i._1_mb_q1_hunger camp#_1_mb_q2_hunger camp#_1_mb_q4_pregnant camp#c._1_mb_child_count ///
camp#_1_mb_q2_fin camp#c._1_hh_res camp#c._1_hh_qua  ///
|| mvid: ||clu2:
testparm i.tx#i._1_child_fem


*HOST
mixed fe_GAD i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==0
testparm i.tx#i._1_child_fem


*CAMP
mixed fe_GAD i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==1
testparm i.tx#i._1_child_fem

/*ENGAGEMENT*/ 
 foreach x in ///
"en_n_f_sum" ///
"en_cb_f_sum" ///
"en_p_f_sum" ///
"en_cm_f_sum" ///
"en_cm_f_sum_alt" ///
"en_d_f_sum" ///
"en_w_f_sum" ///
"sti_f" ///
"fathering" ///
{ 
***********POOLED
mixed e_`x' b_`x' i.tx##i._1_child_fem camp ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
camp#c._1_f_age camp#i.fb_q1_edu camp#i.fb_grade camp#i.fb_q4_edu ///
camp#_1_child_fem camp#c.child_age ///
camp#i._1_mb_q1_hunger camp#_1_mb_q2_hunger camp#_1_mb_q4_pregnant camp#c._1_mb_child_count ///
camp#_1_mb_q2_fin camp#c._1_hh_res camp#c._1_hh_qua  ///
|| mvid: ||clu2:
testparm i.tx#i._1_child_fem


***********HOST
mixed e_`x' b_`x' i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==0
testparm i.tx#i._1_child_fem

***********CAMP

mixed e_`x' b_`x' i.tx##i._1_child_fem ///
_1_f_age i.fb_q1_edu i.fb_grade i.fb_q4_edu ///
_1_child_fem child_age ///
i._1_mb_q1_hunger i._1_mb_q2_hunger _1_mb_q4_pregnant _1_mb_child_count ///
i._1_mb_q2_fin _1_hh_res _1_hh_qua ///
|| mvid: ||clu2: if camp==1
testparm i.tx#i._1_child_fem
} 

*** Note: when running c.mod_edu as the moderator, we do not separately control for i.fb_q1_edu i.fb_grade i.fb_q4_edu or their interaction with camp/host indicator. That would be over-controlling since that information is also included in the c.edu_mod variable.
*** Similarly, when running c.mod_ses as the moderator, we do not separately control for i._1_mb_q2_fin _1_hh_res _1_hh_qua or their interaction with camp/host indicator. That would be over-controlling since that information is also included in the c.mod_ses variable.

